﻿// $Id$
/*! \file
 * \brief Definition of Northwind.DomainModel.EnterpriseLibrary.OrderDetailsMapper.
 *
 * \author $Author$
 * \date $Date$
 * \version $Revision$
 */

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Globalization;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Salamanca.DataAccess;
using Salamanca.DataAccess.Collections;
using Salamanca.DataAccess.EnterpriseLibrary.Data;

namespace Northwind.DomainModel.EnterpriseLibrary
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary />
    ///
    ///////////////////////////////////////////////////////////////////////////

    public partial class OrderDetailsMapper:
        DataMapper<OrderDetails, OrderDetails.PrimaryKey, OrderDetails.DataTransfer>,
        IOrderDetailsMapper
    {

        /// <summary />
        public OrderDetailsMapper(Database database, ICacheManager cacheManager):
            base(database, DomainEntityCreator.CreateDefault<OrderDetails>(), cacheManager)
        {
            _ParameterBuilder=new Salamanca.DataAccess.Data.ParameterBuilder(database.CreateConnection());
        }

        /// <summary />
        public DomainEntityKeyedCollection<OrderDetails> FindAll(DataMapperCollection dataMappers)
        {
            return _FindAll(dataMappers);
        }

        /// <summary />
        public DomainEntityKeyedCollection<OrderDetails> FindByOrder(Order order, DataMapperCollection dataMappers)
        {
            DbCommand[] commands=new DbCommand[1];

            commands[0]=Database.GetSqlStringCommand(
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.Sql.OrderDetailsSelectByOrder,
                    ParameterBuilder.GetMarker("OrderID", 1)
                )
            );

            Database.AddParameter(
                commands[0],
                ParameterBuilder.GetName("OrderID", 1),
                DbType.Int32,
                ParameterDirection.Input,
                string.Empty,
                DataRowVersion.Default,
                order.GetId().Value
            );

            return Load(commands, dataMappers);
        }

        /// <summary />
        protected override IList<DbCommand> CreateSelectCommands(OrderDetails.PrimaryKey key)
        {
            return CreateSelectCommands(Database, ParameterBuilder, key);
        }

        /// <summary />
        protected override IList<DbCommand> CreateDeleteCommands(OrderDetails.DataTransfer data)
        {
            return CreateDeleteCommands(Database, ParameterBuilder, (OrderDetails.DataTransfer)data);
        }

        /// <summary />
        protected override IList<DbCommand> CreateInsertCommands(OrderDetails.DataTransfer data)
        {
            return CreateInsertCommands(Database, ParameterBuilder, (OrderDetails.DataTransfer)data);
        }

        /// <summary />
        protected override IList<DbCommand> CreateUpdateCommands(OrderDetails.DataTransfer data)
        {
            return CreateUpdateCommands(Database, ParameterBuilder, (OrderDetails.DataTransfer)data);
        }

        /// <summary />
        protected override OrderDetails.DataTransfer GetDataTransferObject(IList<IDataRecord> records)
        {
          return _GetDataTransferObject(records);
        }

        /// <summary />
        internal static IList<DbCommand> CreateSelectCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, OrderDetails.PrimaryKey key)
        {
            return new DbCommand[] { _CreateSelectCommand(database, parameterBuilder, key) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateDeleteCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, OrderDetails.DataTransfer data)
        {
            return new DbCommand[] { _CreateDeleteCommand(database, parameterBuilder, (OrderDetails.DataTransfer)data) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateInsertCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, OrderDetails.DataTransfer data)
        {
            return new DbCommand[] { _CreateInsertCommand(database, parameterBuilder, (OrderDetails.DataTransfer)data) };
        }

        /// <summary />
        internal static IList<DbCommand> CreateUpdateCommands(Database database, Salamanca.DataAccess.Data.ParameterBuilder parameterBuilder, OrderDetails.DataTransfer data)
        {
            return new DbCommand[] { _CreateUpdateCommand(database, parameterBuilder, (OrderDetails.DataTransfer)data) };
        }

    }
}
